package com.yxb.square.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.square.domain.TutoringSquare;
import com.yxb.square.service.ITutoringSquareService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 家教广场Controller
 * 
 * @author 林德炫
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/square/square")
public class TutoringSquareController extends BaseController
{
    @Autowired
    private ITutoringSquareService tutoringSquareService;

    /**
     * 查询家教广场列表
     */
    @PreAuthorize("@ss.hasPermi('square:square:list')")
    @GetMapping("/list")
    public TableDataInfo list(TutoringSquare tutoringSquare)
    {
//        System.out.println("1111111111111111111111111111111111111111111111111"+tutoringSquare);
        startPage();
        List<TutoringSquare> list = tutoringSquareService.selectTutoringSquareList(tutoringSquare);
        return getDataTable(list);
    }

    /**
     * 根据接单状态（非“待接单”）获取家教广场列表
     * 教员接单页信息
     */
    @PreAuthorize("@ss.hasPermi('square:square:listSquareByStatus')")
    @GetMapping( "/listSquareByStatus")
    public TableDataInfo listByStatus(TutoringSquare tutoringSquare)
    {
//        System.out.println("66666666666666666666666"+tutoringSquare);
        startPage();
        List<TutoringSquare> listByStatus = tutoringSquareService.selectListByStatus(tutoringSquare);
        return getDataTable(listByStatus);
    }

    /**
     * 导出家教广场列表
     */
    @PreAuthorize("@ss.hasPermi('square:square:export')")
    @Log(title = "家教广场", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TutoringSquare tutoringSquare)
    {
        List<TutoringSquare> list = tutoringSquareService.selectTutoringSquareList(tutoringSquare);
        ExcelUtil<TutoringSquare> util = new ExcelUtil<TutoringSquare>(TutoringSquare.class);
        util.exportExcel(response, list, "家教广场数据");
    }

    /**
     * 根据教员名查询接单列表（支持分页和发布人名称过滤）
     */
    @GetMapping("/listSquareByTeacher")
    public TableDataInfo listSquareByTeacher(
            @RequestParam("teacherName") String teacherName,
            @RequestParam(value = "name", required = false) String name)
    {
        startPage(); // 隐式从请求中提取 pageNum 和 pageSize
        List<TutoringSquare> list = tutoringSquareService.listSquareByTeacher(teacherName, name);
        return getDataTable(list);
    }

    /**
     * 根据家长名查询家教广场列表（新增状态筛选）
     */
    @GetMapping("/listSquareByParent")
    public TableDataInfo listSquareByParent(
            @RequestParam("parentName") String parentName,
            @RequestParam(value = "status", required = false) String status) // 可选参数
    {
        startPage();
        List<TutoringSquare> list = tutoringSquareService.listSquareByParent(parentName, status);
        return getDataTable(list);
    }


    /**
     * 根据用户名查询家教广场列表
     */
    @GetMapping(value = "listSquareByUserName/{userName}")
    public TableDataInfo listSquareByUserName(@PathVariable("userName") String userName) {
        startPage();
        List<TutoringSquare> list = tutoringSquareService.listSquareByUserName(userName);
        return getDataTable(list);
    }
    /**
     * 获取家教广场详细信息
     */
    @PreAuthorize("@ss.hasPermi('square:square:query')")
    @GetMapping(value = "/{requestId}")
    public AjaxResult getInfo(@PathVariable("requestId") Long requestId)
    {
//        System.out.println("222222222222222222222222222222222"+tutoringSquareService.selectTutoringSquareByRequestId(requestId));
        return success(tutoringSquareService.selectTutoringSquareByRequestId(requestId));
    }


    /**
     * 新增家教广场
     */
    @PreAuthorize("@ss.hasPermi('square:square:add')")
    @Log(title = "家教广场", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TutoringSquare tutoringSquare)
    {
//        System.out.println("1111111111111111111111111111111111111111111111111"+tutoringSquare);
        return toAjax(tutoringSquareService.insertTutoringSquare(tutoringSquare));
    }

    /**
     * 修改家教广场
     */
    @PreAuthorize("@ss.hasPermi('square:square:edit')")
    @Log(title = "家教广场", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TutoringSquare tutoringSquare)
    {
//        System.out.println("林德炫"+tutoringSquare);
        return toAjax(tutoringSquareService.updateTutoringSquare(tutoringSquare));
    }


    /**
     * 删除家教广场
     */
    @PreAuthorize("@ss.hasPermi('square:square:remove')")
    @Log(title = "家教广场", businessType = BusinessType.DELETE)
	@DeleteMapping("/{requestIds}")
    public AjaxResult remove(@PathVariable Long[] requestIds)
    {
        return toAjax(tutoringSquareService.deleteTutoringSquareByRequestIds(requestIds));
    }
}
